package com.zzyl.service.impl;


import com.zzyl.dto.FloorDto;
import com.zzyl.entity.live.Floor;
import com.zzyl.mapper.FloorMapper;
import com.zzyl.service.BedService;
import com.zzyl.service.FloorService;
import com.zzyl.service.RoomService;
import com.zzyl.vo.FloorVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
@RequiredArgsConstructor
public class FloorServiceImpl implements FloorService {
	
	private final RoomService roomService;
	
	private final BedService bedService;
	
	private final FloorMapper floorMapper;
	
	//增加楼层
	@Override
	public void addFloor(FloorDto floorDto) {
		Floor floor = new Floor();
		BeanUtils.copyProperties(floorDto, floor);
		floorMapper.insert(floor);
	}
	
	
	//通过ID删除楼层
	@Override
	public void deleteFloor(Long id) {
		floorMapper.deleteById(id);
	}
	
	
	//更新楼层信息
	@Override
	public void updateFloor(FloorDto floorDto) {
		Floor floor = new Floor();
		BeanUtils.copyProperties(floorDto, floor);
		floor.setUpdateTime(LocalDateTime.now());
		floorMapper.updateById(floor);
	}
	
	
	//通过ID查询楼层信息
	@Override
	public FloorVo getFloor(Long id) {
		Floor floor = floorMapper.selectById(id);
		FloorVo floorVo = new FloorVo();
		BeanUtils.copyProperties(floor, floorVo);
		return floorVo;
	}
	
	//获取所有的楼层信息
	@Override
	public List<FloorVo> getAllFloors() {
		return floorMapper.selectAll();
	}
	
	@Override
	public List<FloorVo> getAllWithRoomAndBed() {
		return floorMapper.selectAllRoomAndBed();
	}
	
	@Override
	public List<FloorVo> selectAllByNur() {
		return floorMapper.selectAllByNur();
	}
	
}

